home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / netinclude / rpc / clnt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-21  |  8.8 KB  |  326 lines

  1. /*
  2.  * $Id: clnt.h,v 1.2 1993/11/10 00:41:01 jraja Exp $
  3.  *
  4.  * $Log: clnt.h,v $
  5.  * Revision 1.2  1993/11/10  00:41:01  jraja
  6.  * ANSI prototypes.
  7.  * Added prototype for the callrpc().
  8.  *
  9.  */
  10. /* @(#)clnt.h    2.1 88/07/29 4.0 RPCSRC; from 1.31 88/02/08 SMI*/
  11. /*
  12.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  13.  * unrestricted use provided that this legend is included on all tape
  14.  * media and as a part of the software program in whole or part.  Users
  15.  * may copy or modify Sun RPC without charge, but are not authorized
  16.  * to license or distribute it to anyone else except as part of a product or
  17.  * program developed by the user.
  18.  * 
  19.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  20.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  21.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  22.  * 
  23.  * Sun RPC is provided with no support and without any obligation on the
  24.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  25.  * modification or enhancement.
  26.  * 
  27.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  28.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  29.  * OR ANY PART THEREOF.
  30.  * 
  31.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  32.  * or profits or other special, indirect and consequential damages, even if
  33.  * Sun has been advised of the possibility of such damages.
  34.  * 
  35.  * Sun Microsystems, Inc.
  36.  * 2550 Garcia Avenue
  37.  * Mountain View, California  94043
  38.  */
  39.  
  40. /*
  41.  * clnt.h - Client side remote procedure call interface.
  42.  *
  43.  * Copyright (C) 1984, Sun Microsystems, Inc.
  44.  */
  45.  
  46. #ifndef _CLNT_
  47. #define _CLNT_
  48.  
  49. /*
  50.  * Rpc calls return an enum clnt_stat.  This should be looked at more,
  51.  * since each implementation is required to live with this (implementation
  52.  * independent) list of errors.
  53.  */
  54. enum clnt_stat {
  55.     RPC_SUCCESS=0,            /* call succeeded */
  56.     /*
  57.      * local errors
  58.      */
  59.     RPC_CANTENCODEARGS=1,        /* can't encode arguments */
  60.     RPC_CANTDECODERES=2,        /* can't decode results */
  61.     RPC_CANTSEND=3,            /* failure in sending call */
  62.     RPC_CANTRECV=4,            /* failure in receiving result */
  63.     RPC_TIMEDOUT=5,            /* call timed out */
  64.     /*
  65.      * remote errors
  66.      */
  67.     RPC_VERSMISMATCH=6,        /* rpc versions not compatible */
  68.     RPC_AUTHERROR=7,        /* authentication error */
  69.     RPC_PROGUNAVAIL=8,        /* program not available */
  70.     RPC_PROGVERSMISMATCH=9,        /* program version mismatched */
  71.     RPC_PROCUNAVAIL=10,        /* procedure unavailable */
  72.     RPC_CANTDECODEARGS=11,        /* decode arguments error */
  73.     RPC_SYSTEMERROR=12,        /* generic "other problem" */
  74.  
  75.     /*
  76.      * callrpc & clnt_create errors
  77.      */
  78.     RPC_UNKNOWNHOST=13,        /* unknown host name */
  79.     RPC_UNKNOWNPROTO=17,        /* unkown protocol */
  80.  
  81.     /*
  82.      * _ create errors
  83.      */
  84.     RPC_PMAPFAILURE=14,        /* the pmapper failed in its call */
  85.     RPC_PROGNOTREGISTERED=15,    /* remote program is not registered */
  86.     /*
  87.      * unspecified error
  88.      */
  89.     RPC_FAILED=16
  90. };
  91.  
  92.  
  93. /*
  94.  * Error info.
  95.  */
  96. struct rpc_err {
  97.     enum clnt_stat re_status;
  98.     union {
  99.         int RE_errno;        /* realated system error */
  100.         enum auth_stat RE_why;    /* why the auth error occurred */
  101.         struct {
  102.             u_long low;    /* lowest verion supported */
  103.             u_long high;    /* highest verion supported */
  104.         } RE_vers;
  105.         struct {        /* maybe meaningful if RPC_FAILED */
  106.             long s1;
  107.             long s2;
  108.         } RE_lb;        /* life boot & debugging only */
  109.     } ru;
  110. #define    re_errno    ru.RE_errno
  111. #define    re_why        ru.RE_why
  112. #define    re_vers        ru.RE_vers
  113. #define    re_lb        ru.RE_lb
  114. };
  115.  
  116.  
  117. /*
  118.  * Client rpc handle.
  119.  * Created by individual implementations, see e.g. rpc_udp.c.
  120.  * Client is responsible for initializing auth, see e.g. auth_none.c.
  121.  */
  122. typedef struct CLIENT {
  123.     AUTH    *cl_auth;            /* authenticator */
  124.     struct clnt_ops {
  125.         enum clnt_stat    (*cl_call)(struct CLIENT *rh, u_long proc, 
  126.                        xdrproc_t xargs, void * argsp, 
  127.                        xdrproc_t xres, void * resp, 
  128.                        struct timeval timeout);    /* call remote procedure */
  129.         void        (*cl_abort)(struct CLIENT *rh);    /* abort a call */
  130.         void        (*cl_geterr)(struct CLIENT *rh, 
  131.                          struct rpc_err *errp); /* get specific error code */
  132.         bool_t        (*cl_freeres)(struct CLIENT *rh, 
  133.                           xdrproc_t xres, void * resp); /* frees results */
  134.         void        (*cl_destroy)(struct CLIENT *rh); /* destroy this structure */
  135.         bool_t          (*cl_control)(struct CLIENT *rh, u_int request,
  136.                           void * info); /* the ioctl() of rpc */
  137.     } *cl_ops;
  138.     caddr_t            cl_private;    /* private stuff */
  139. } CLIENT;
  140.  
  141.  
  142. /*
  143.  * client side rpc interface ops
  144.  *
  145.  * Parameter types are:
  146.  *
  147.  */
  148.  
  149. /*
  150.  * enum clnt_stat
  151.  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  152.  *     CLIENT *rh;
  153.  *    u_long proc;
  154.  *    xdrproc_t xargs;
  155.  *    void * argsp;
  156.  *    xdrproc_t xres;
  157.  *    void * resp;
  158.  *    struct timeval timeout;
  159.  */
  160. #define    CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)    \
  161.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  162. #define    clnt_call(rh, proc, xargs, argsp, xres, resp, secs)    \
  163.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  164.  
  165. /*
  166.  * void
  167.  * CLNT_ABORT(rh);
  168.  *     CLIENT *rh;
  169.  */
  170. #define    CLNT_ABORT(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  171. #define    clnt_abort(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  172.  
  173. /*
  174.  * void
  175.  * CLNT_GETERR(rh, errp);
  176.  *     CLIENT *rh;
  177.  *      struct rpc_err *errp;
  178.  */
  179. #define    CLNT_GETERR(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  180. #define    clnt_geterr(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  181.  
  182.  
  183. /*
  184.  * bool_t
  185.  * CLNT_FREERES(rh, xres, resp);
  186.  *     CLIENT *rh;
  187.  *    xdrproc_t xres;
  188.  *    void * resp;
  189.  */
  190. #define    CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  191. #define    clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  192.  
  193. /*
  194.  * bool_t
  195.  * CLNT_CONTROL(cl, request, info)
  196.  *      CLIENT *cl;
  197.  *      u_int request;
  198.  *      void *info;
  199.  */
  200. #define    CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  201. #define    clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  202.  
  203. /*
  204.  * control operations that apply to both udp and tcp transports
  205.  */
  206. #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
  207. #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
  208. #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
  209. /*
  210.  * udp only control operations
  211.  */
  212. #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
  213. #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
  214.  
  215. /*
  216.  * void
  217.  * CLNT_DESTROY(rh);
  218.  *     CLIENT *rh;
  219.  */
  220. #define    CLNT_DESTROY(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  221. #define    clnt_destroy(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  222.  
  223.  
  224. /*
  225.  * RPCTEST is a test program which is accessable on every rpc
  226.  * transport/port.  It is used for testing, performance evaluation,
  227.  * and network administration.
  228.  */
  229.  
  230. #define RPCTEST_PROGRAM        (1UL)
  231. #define RPCTEST_VERSION        (1UL)
  232. #define RPCTEST_NULL_PROC    (2UL)
  233. #define RPCTEST_NULL_BATCH_PROC    (3UL)
  234.  
  235. /*
  236.  * By convention, procedure 0 takes null arguments and returns them
  237.  */
  238.  
  239. #define NULLPROC (0UL)
  240.  
  241. /*
  242.  * Below are the client handle creation routines for the various
  243.  * implementations of client side rpc.  They can return NULL if a 
  244.  * creation failure occurs.
  245.  */
  246.  
  247. /*
  248.  * Memory based rpc (for speed check and testing)
  249.  */
  250. extern CLIENT *clntraw_create(u_long prog, u_long vers);
  251.  
  252.  
  253. /*
  254.  * Generic client creation routine. Supported protocols are "udp" and "tcp"
  255.  */
  256. extern CLIENT *
  257. clnt_create(char *host, u_long prog, u_long vers, char *prot);
  258.  
  259.  
  260. /*
  261.  * TCP based rpc
  262.  */
  263. extern CLIENT *clnttcp_create(struct sockaddr_in *raddr, u_long prog, 
  264.                   u_long version, int *sockp,
  265.                   u_int sendsz, u_int recvsz);
  266.  
  267. /*
  268.  * UDP based rpc.
  269.  */
  270. extern CLIENT *clntudp_create(struct sockaddr_in *raddr, u_long program,
  271.                   u_long version, struct timeval wait, int *sockp);
  272. /*
  273.  * Same as above, but you specify max packet sizes.
  274.  */
  275. extern CLIENT *clntudp_bufcreate(struct sockaddr_in *raddr, u_long program,
  276.                  u_long version, struct timeval wait, 
  277.                  int *sockp, u_int sendsz, u_int recvsz);
  278.  
  279. /*
  280.  * Print why creation failed
  281.  */
  282. extern void clnt_pcreateerror(char *msg);    /* stderr */
  283. extern char *clnt_spcreateerror(char *msg);    /* string */
  284.  
  285. /*
  286.  * Like clnt_perror(), but is more verbose in its output
  287.  */ 
  288. extern void clnt_perrno(enum clnt_stat num);    /* stderr */
  289.  
  290. /*
  291.  * Print an English error message, given the client error code
  292.  */
  293. extern void clnt_perror(CLIENT *clnt, char *msg);     /* stderr */
  294. extern char *clnt_sperror(CLIENT *clnt, char *msg);    /* string */
  295.  
  296. /* 
  297.  * If a creation fails, the following allows the user to figure out why.
  298.  */
  299. struct rpc_createerr {
  300.     enum clnt_stat cf_stat;
  301.     struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  302. };
  303.  
  304. extern struct rpc_createerr rpc_createerr;
  305.  
  306.  
  307.  
  308. /*
  309.  * Copy error message to buffer.
  310.  */
  311. extern char *clnt_sperrno(enum clnt_stat num);    /* string */
  312.  
  313.  
  314.  
  315. #define UDPMSGSIZE    8800    /* rpc imposed limit on udp msg size */
  316. #define RPCSMALLMSGSIZE    400    /* a more reasonable packet size */
  317.  
  318. /*
  319.  * simple rpc
  320.  */
  321. int callrpc(const char * host,
  322.         u_long prognum, u_long versnum, u_long procnum,
  323.         xdrproc_t inproc, void * in, xdrproc_t outproc, void * out);
  324.  
  325. #endif /*!_CLNT_*/
  326.